package com.hjw.weixun.action;

import java.util.List;

import com.hjw.weixun.domain.Message;
import com.hjw.weixun.domain.User;
import com.hjw.weixun.domain.Weixun;
import com.hjw.weixun.service.FollowerService;
import com.hjw.weixun.service.MessageService;
import com.hjw.weixun.service.UserService;
import com.hjw.weixun.service.WeixunService;
import com.hjw.weixun.service.impl.FollowerServiceImpl;
import com.hjw.weixun.service.impl.MessageServiceImpl;
import com.hjw.weixun.service.impl.UserServiceImpl;
import com.hjw.weixun.service.impl.WeixunServiceImpl;

/**
 * 微讯平台的管理
 * 
 * @author wangchangxin
 * 
 */
public class WeixunAction extends GenericAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7075630643474742341L;

	private WeixunService weixunService;

	private FollowerService followerService;

	private MessageService messageService;

	private UserService userService;

	private boolean followState;

	private Weixun weixun;

	private List<Message> messageList;

	private List<User> followerList;

	private String path;

	public WeixunAction() {
		weixunService = WeixunServiceImpl.getInstance();
		followerService = FollowerServiceImpl.getInstance();
		messageService = MessageServiceImpl.getInstance();
		userService = UserServiceImpl.getInstance();
	}
	
	

	@Override
	public String execute() throws Exception {
		return getWeixunInfo();
	}



	public String getWeixunInfo() {

		path = "message/microNews.jsp";

		User user = super.getCurrentUser();

		if (null == user) {
			return ERROR;
		}

		if (null != weixun) {
			weixun = weixunService.getWeixunByPath(weixun);
			// 判断是否已经关注过
			followState = followerService.isFollower(weixun, user);

			messageList = messageService.getMessageList(weixun);

			followerList = userService.getFollowedList(weixun);
		}

		return SUCCESS;
	}

	public Weixun getWeixun() {
		return weixun;
	}

	public void setWeixun(Weixun weixun) {
		this.weixun = weixun;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public boolean isFollowState() {
		return followState;
	}

	public void setFollowState(boolean followState) {
		this.followState = followState;
	}

	public List<Message> getMessageList() {
		return messageList;
	}

	public void setMessageList(List<Message> messageList) {
		this.messageList = messageList;
	}

	public List<User> getFollowerList() {
		return followerList;
	}

	public void setFollowerList(List<User> followerList) {
		this.followerList = followerList;
	}

}
